<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.9.2"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>kalman-cpp: kalman/ekf.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js"],
    jax: ["input/TeX","output/HTML-CSS"],
});
</script>
<script type="text/javascript" async="async" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript/MathJax.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">kalman-cpp
   </div>
   <div id="projectbrief">Implementation of Kalman Filter in C++</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.2 -->
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',false,false,'search.php','Search');
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('ekf_8h_source.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">ekf.h</div>  </div>
</div><!--header-->
<div class="contents">
<a href="ekf_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160; </div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;<span class="preprocessor">#ifndef EKF_H</span></div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;<span class="preprocessor">#define EKF_H</span></div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160; </div>
<div class="line"><a name="l00024"></a><span class="lineno"><a class="line" href="ekf_8h.html#a525335710b53cb064ca56b936120431e">   24</a></span>&#160;<span class="preprocessor">#define _USE_MATH_DEFINES</span></div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;<span class="preprocessor">#include &lt;math.h&gt;</span></div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160; </div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;<span class="preprocessor">#include &lt;assert.h&gt;</span></div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;<span class="preprocessor">#include &lt;armadillo&gt;</span></div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160; </div>
<div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;<span class="keyword">using namespace </span>std;</div>
<div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;<span class="keyword">using namespace </span>arma;</div>
<div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160; </div>
<div class="line"><a name="l00037"></a><span class="lineno"><a class="line" href="class_e_k_f.html">   37</a></span>&#160;<span class="keyword">class </span><a class="code" href="class_e_k_f.html">EKF</a> {</div>
<div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;<span class="keyword">public</span>:  </div>
<div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;  <a class="code" href="class_e_k_f.html#ab48b75de3b276773f474e347ebc5b2a0">EKF</a>();</div>
<div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;  </div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;  <a class="code" href="class_e_k_f.html#abebda258b361ad3ceb05a70ae453baec">~EKF</a>();</div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;  </div>
<div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;  <span class="keywordtype">void</span> <a class="code" href="class_e_k_f.html#a9d8af910c1a469ff5f4d5feaa9a24258">InitSystem</a>(<span class="keywordtype">int</span> n_states, <span class="keywordtype">int</span> n_outputs, <span class="keyword">const</span> mat&amp; Q, <span class="keyword">const</span> mat&amp; R);</div>
<div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;  <span class="keyword">virtual</span> colvec <a class="code" href="class_e_k_f.html#a6c084d493687d9ad0cf55d8c97c22633">f</a>(<span class="keyword">const</span> colvec &amp;x, <span class="keyword">const</span> colvec &amp;u);</div>
<div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;  </div>
<div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;  <span class="keyword">virtual</span> colvec <a class="code" href="class_e_k_f.html#acb8638938ff97e5839e02f24860243e5">h</a>(<span class="keyword">const</span> colvec &amp;x);</div>
<div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;  <span class="keywordtype">void</span> <a class="code" href="class_e_k_f.html#a4d44ac37102771fa49824b073a532670">InitSystemState</a>(<span class="keyword">const</span> colvec&amp; x0);</div>
<div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;  </div>
<div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;  <span class="keywordtype">void</span> <a class="code" href="class_e_k_f.html#a55196ac6b48e2ded166834a0c1df53cf">InitSystemStateCovariance</a>(<span class="keyword">const</span> mat&amp; P0);</div>
<div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160; </div>
<div class="line"><a name="l00090"></a><span class="lineno">   90</span>&#160;  <span class="keywordtype">void</span> <a class="code" href="class_e_k_f.html#a135d2b0e0132492693fd5c6ebe650893">EKalmanf</a>(<span class="keyword">const</span> colvec&amp; u);</div>
<div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;  </div>
<div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160;  <span class="keywordtype">void</span> <a class="code" href="class_e_k_f.html#a135d2b0e0132492693fd5c6ebe650893">EKalmanf</a>(<span class="keyword">const</span> colvec&amp; z, <span class="keyword">const</span> colvec&amp; u);</div>
<div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;  </div>
<div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;  colvec* <a class="code" href="class_e_k_f.html#af1efb20e6f88cf39cc80d8c83bb41ae5">GetCurrentState</a>();</div>
<div class="line"><a name="l00107"></a><span class="lineno">  107</span>&#160;  </div>
<div class="line"><a name="l00113"></a><span class="lineno">  113</span>&#160;  colvec* <a class="code" href="class_e_k_f.html#a8ff98a83a909c1a73e7c54fb6bed9c4c">GetCurrentOutput</a>();</div>
<div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160;  </div>
<div class="line"><a name="l00120"></a><span class="lineno">  120</span>&#160;  colvec* <a class="code" href="class_e_k_f.html#ad8dcb50f6cd1dcaa313c8e90706c5dca">GetCurrentEstimatedState</a>();</div>
<div class="line"><a name="l00121"></a><span class="lineno">  121</span>&#160;  </div>
<div class="line"><a name="l00126"></a><span class="lineno">  126</span>&#160;  colvec* <a class="code" href="class_e_k_f.html#a12968bc0cfc1e2ff922afedce318dd7b">GetCurrentEstimatedOutput</a>();</div>
<div class="line"><a name="l00127"></a><span class="lineno">  127</span>&#160;  </div>
<div class="line"><a name="l00128"></a><span class="lineno">  128</span>&#160;<span class="keyword">private</span>:</div>
<div class="line"><a name="l00135"></a><span class="lineno">  135</span>&#160;  <span class="keywordtype">void</span> CalcF(<span class="keyword">const</span> colvec &amp;x, <span class="keyword">const</span> colvec &amp;u);</div>
<div class="line"><a name="l00136"></a><span class="lineno">  136</span>&#160;  </div>
<div class="line"><a name="l00142"></a><span class="lineno">  142</span>&#160;  <span class="keywordtype">void</span> CalcH(<span class="keyword">const</span> colvec &amp;x);</div>
<div class="line"><a name="l00143"></a><span class="lineno">  143</span>&#160; </div>
<div class="line"><a name="l00144"></a><span class="lineno">  144</span>&#160;  mat F_;          </div>
<div class="line"><a name="l00145"></a><span class="lineno">  145</span>&#160;  mat H_;          </div>
<div class="line"><a name="l00146"></a><span class="lineno">  146</span>&#160;  mat Q_;          </div>
<div class="line"><a name="l00147"></a><span class="lineno">  147</span>&#160;  mat R_;          </div>
<div class="line"><a name="l00148"></a><span class="lineno">  148</span>&#160;  colvec v_;       </div>
<div class="line"><a name="l00149"></a><span class="lineno">  149</span>&#160;  colvec w_;       </div>
<div class="line"><a name="l00150"></a><span class="lineno">  150</span>&#160;  </div>
<div class="line"><a name="l00151"></a><span class="lineno">  151</span>&#160;  mat sqrt_Q_;     </div>
<div class="line"><a name="l00152"></a><span class="lineno">  152</span>&#160;  mat sqrt_R_;     </div>
<div class="line"><a name="l00153"></a><span class="lineno">  153</span>&#160;  </div>
<div class="line"><a name="l00154"></a><span class="lineno">  154</span>&#160; </div>
<div class="line"><a name="l00155"></a><span class="lineno">  155</span>&#160; </div>
<div class="line"><a name="l00156"></a><span class="lineno">  156</span>&#160;  colvec x_m_;     </div>
<div class="line"><a name="l00157"></a><span class="lineno">  157</span>&#160;  colvec x_p_;     </div>
<div class="line"><a name="l00158"></a><span class="lineno">  158</span>&#160;  </div>
<div class="line"><a name="l00159"></a><span class="lineno">  159</span>&#160;  mat P_p_;        </div>
<div class="line"><a name="l00160"></a><span class="lineno">  160</span>&#160;  mat P_m_;        </div>
<div class="line"><a name="l00161"></a><span class="lineno">  161</span>&#160;  </div>
<div class="line"><a name="l00162"></a><span class="lineno">  162</span>&#160;  colvec z_m_;     </div>
<div class="line"><a name="l00163"></a><span class="lineno">  163</span>&#160;  </div>
<div class="line"><a name="l00164"></a><span class="lineno">  164</span>&#160;  <span class="keywordtype">double</span> epsilon_; </div>
<div class="line"><a name="l00165"></a><span class="lineno">  165</span>&#160; </div>
<div class="line"><a name="l00166"></a><span class="lineno">  166</span>&#160;<span class="keyword">protected</span>:</div>
<div class="line"><a name="l00167"></a><span class="lineno">  167</span>&#160;  </div>
<div class="line"><a name="l00168"></a><span class="lineno"><a class="line" href="class_e_k_f.html#ae27fd423477a96fd15665ae15a5e55e5">  168</a></span>&#160;  <span class="keywordtype">int</span> <a class="code" href="class_e_k_f.html#ae27fd423477a96fd15665ae15a5e55e5">nStates_</a>;   </div>
<div class="line"><a name="l00169"></a><span class="lineno"><a class="line" href="class_e_k_f.html#a8902f8ab6a6a8d46524e2a501716d09e">  169</a></span>&#160;  <span class="keywordtype">int</span> <a class="code" href="class_e_k_f.html#a8902f8ab6a6a8d46524e2a501716d09e">nOutputs_</a>;  </div>
<div class="line"><a name="l00170"></a><span class="lineno">  170</span>&#160;  </div>
<div class="line"><a name="l00171"></a><span class="lineno"><a class="line" href="class_e_k_f.html#a262cd1dead985261fa576cf4ca7721ff">  171</a></span>&#160;  colvec <a class="code" href="class_e_k_f.html#a262cd1dead985261fa576cf4ca7721ff">x_</a>;      </div>
<div class="line"><a name="l00172"></a><span class="lineno"><a class="line" href="class_e_k_f.html#a4faca49ecd115b274373579090514fcc">  172</a></span>&#160;  colvec <a class="code" href="class_e_k_f.html#a4faca49ecd115b274373579090514fcc">z_</a>;      </div>
<div class="line"><a name="l00173"></a><span class="lineno">  173</span>&#160;};</div>
<div class="line"><a name="l00174"></a><span class="lineno">  174</span>&#160; </div>
<div class="line"><a name="l00175"></a><span class="lineno">  175</span>&#160; </div>
<div class="line"><a name="l00176"></a><span class="lineno">  176</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="ttc" id="aclass_e_k_f_html"><div class="ttname"><a href="class_e_k_f.html">EKF</a></div><div class="ttdoc">Implemetation of the extended Kalman filter. This class needs to be derived.</div><div class="ttdef"><b>Definition:</b> ekf.h:37</div></div>
<div class="ttc" id="aclass_e_k_f_html_a12968bc0cfc1e2ff922afedce318dd7b"><div class="ttname"><a href="class_e_k_f.html#a12968bc0cfc1e2ff922afedce318dd7b">EKF::GetCurrentEstimatedOutput</a></div><div class="ttdeci">colvec * GetCurrentEstimatedOutput()</div><div class="ttdoc">Get current estimated output.</div><div class="ttdef"><b>Definition:</b> ekf.cpp:186</div></div>
<div class="ttc" id="aclass_e_k_f_html_a135d2b0e0132492693fd5c6ebe650893"><div class="ttname"><a href="class_e_k_f.html#a135d2b0e0132492693fd5c6ebe650893">EKF::EKalmanf</a></div><div class="ttdeci">void EKalmanf(const colvec &amp;u)</div><div class="ttdoc">Do the extended Kalman iteration step-by-step while simulating the system. Simulating the system is d...</div><div class="ttdef"><b>Definition:</b> ekf.cpp:125</div></div>
<div class="ttc" id="aclass_e_k_f_html_a262cd1dead985261fa576cf4ca7721ff"><div class="ttname"><a href="class_e_k_f.html#a262cd1dead985261fa576cf4ca7721ff">EKF::x_</a></div><div class="ttdeci">colvec x_</div><div class="ttdoc">State vector.</div><div class="ttdef"><b>Definition:</b> ekf.h:171</div></div>
<div class="ttc" id="aclass_e_k_f_html_a4d44ac37102771fa49824b073a532670"><div class="ttname"><a href="class_e_k_f.html#a4d44ac37102771fa49824b073a532670">EKF::InitSystemState</a></div><div class="ttdeci">void InitSystemState(const colvec &amp;x0)</div><div class="ttdoc">Initialize the system states. Must be called after InitSystem. If not called, system state is initial...</div><div class="ttdef"><b>Definition:</b> ekf.cpp:111</div></div>
<div class="ttc" id="aclass_e_k_f_html_a4faca49ecd115b274373579090514fcc"><div class="ttname"><a href="class_e_k_f.html#a4faca49ecd115b274373579090514fcc">EKF::z_</a></div><div class="ttdeci">colvec z_</div><div class="ttdoc">Output matrix.</div><div class="ttdef"><b>Definition:</b> ekf.h:172</div></div>
<div class="ttc" id="aclass_e_k_f_html_a55196ac6b48e2ded166834a0c1df53cf"><div class="ttname"><a href="class_e_k_f.html#a55196ac6b48e2ded166834a0c1df53cf">EKF::InitSystemStateCovariance</a></div><div class="ttdeci">void InitSystemStateCovariance(const mat &amp;P0)</div><div class="ttdoc">Initialize the system state covariance. Must be called after InitSystem. If not called,...</div><div class="ttdef"><b>Definition:</b> ekf.cpp:118</div></div>
<div class="ttc" id="aclass_e_k_f_html_a6c084d493687d9ad0cf55d8c97c22633"><div class="ttname"><a href="class_e_k_f.html#a6c084d493687d9ad0cf55d8c97c22633">EKF::f</a></div><div class="ttdeci">virtual colvec f(const colvec &amp;x, const colvec &amp;u)</div><div class="ttdoc">Define model of your system.</div><div class="ttdef"><b>Definition:</b> ekf.cpp:60</div></div>
<div class="ttc" id="aclass_e_k_f_html_a8902f8ab6a6a8d46524e2a501716d09e"><div class="ttname"><a href="class_e_k_f.html#a8902f8ab6a6a8d46524e2a501716d09e">EKF::nOutputs_</a></div><div class="ttdeci">int nOutputs_</div><div class="ttdoc">Number of outputs.</div><div class="ttdef"><b>Definition:</b> ekf.h:169</div></div>
<div class="ttc" id="aclass_e_k_f_html_a8ff98a83a909c1a73e7c54fb6bed9c4c"><div class="ttname"><a href="class_e_k_f.html#a8ff98a83a909c1a73e7c54fb6bed9c4c">EKF::GetCurrentOutput</a></div><div class="ttdeci">colvec * GetCurrentOutput()</div><div class="ttdoc">Get current simulated true output. This is analogous to the measurements.</div><div class="ttdef"><b>Definition:</b> ekf.cpp:175</div></div>
<div class="ttc" id="aclass_e_k_f_html_a9d8af910c1a469ff5f4d5feaa9a24258"><div class="ttname"><a href="class_e_k_f.html#a9d8af910c1a469ff5f4d5feaa9a24258">EKF::InitSystem</a></div><div class="ttdeci">void InitSystem(int n_states, int n_outputs, const mat &amp;Q, const mat &amp;R)</div><div class="ttdoc">Tell me how many states and outputs you have!</div><div class="ttdef"><b>Definition:</b> ekf.cpp:20</div></div>
<div class="ttc" id="aclass_e_k_f_html_ab48b75de3b276773f474e347ebc5b2a0"><div class="ttname"><a href="class_e_k_f.html#ab48b75de3b276773f474e347ebc5b2a0">EKF::EKF</a></div><div class="ttdeci">EKF()</div><div class="ttdoc">Constructor, nothing happens here.</div><div class="ttdef"><b>Definition:</b> ekf.cpp:10</div></div>
<div class="ttc" id="aclass_e_k_f_html_abebda258b361ad3ceb05a70ae453baec"><div class="ttname"><a href="class_e_k_f.html#abebda258b361ad3ceb05a70ae453baec">EKF::~EKF</a></div><div class="ttdeci">~EKF()</div><div class="ttdoc">Destructur, nothing happens here.</div><div class="ttdef"><b>Definition:</b> ekf.cpp:15</div></div>
<div class="ttc" id="aclass_e_k_f_html_acb8638938ff97e5839e02f24860243e5"><div class="ttname"><a href="class_e_k_f.html#acb8638938ff97e5839e02f24860243e5">EKF::h</a></div><div class="ttdeci">virtual colvec h(const colvec &amp;x)</div><div class="ttdoc">Define the output model of your system.</div><div class="ttdef"><b>Definition:</b> ekf.cpp:67</div></div>
<div class="ttc" id="aclass_e_k_f_html_ad8dcb50f6cd1dcaa313c8e90706c5dca"><div class="ttname"><a href="class_e_k_f.html#ad8dcb50f6cd1dcaa313c8e90706c5dca">EKF::GetCurrentEstimatedState</a></div><div class="ttdeci">colvec * GetCurrentEstimatedState()</div><div class="ttdoc">Get current estimated state. This is analogous to the filtered measurements.</div><div class="ttdef"><b>Definition:</b> ekf.cpp:180</div></div>
<div class="ttc" id="aclass_e_k_f_html_ae27fd423477a96fd15665ae15a5e55e5"><div class="ttname"><a href="class_e_k_f.html#ae27fd423477a96fd15665ae15a5e55e5">EKF::nStates_</a></div><div class="ttdeci">int nStates_</div><div class="ttdoc">Number of the states.</div><div class="ttdef"><b>Definition:</b> ekf.h:168</div></div>
<div class="ttc" id="aclass_e_k_f_html_af1efb20e6f88cf39cc80d8c83bb41ae5"><div class="ttname"><a href="class_e_k_f.html#af1efb20e6f88cf39cc80d8c83bb41ae5">EKF::GetCurrentState</a></div><div class="ttdeci">colvec * GetCurrentState()</div><div class="ttdoc">Get current simulated true state.</div><div class="ttdef"><b>Definition:</b> ekf.cpp:170</div></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="dir_dc133b73f91f0e3b4287924ed00a2a00.html">kalman</a></li><li class="navelem"><a class="el" href="ekf_8h.html">ekf.h</a></li>
    <li class="footer">Generated on Thu Apr 1 2021 04:15:37 for kalman-cpp by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.2 </li>
  </ul>
</div>
</body>
</html>
